package com.dfbz.demo01_实现TCP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo04_接收端 {
    public static void main(String[] args) throws IOException {

        // 接收端
        DatagramSocket socket = new DatagramSocket(8989);

        byte[] data = new byte[1024];
        DatagramPacket packet = new DatagramPacket(data, data.length);

        // 将socket接收到的UDP报文赋值给packet
        socket.receive(packet);

        socket.close();

        System.out.println("接收到了数据: " + new String(data, 0,packet.getLength()));
    }
}
